package com.laze.mywanandroid.ui.main.fragment.home

import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hjq.toast.ToastUtils
import com.laze.mywanandroid.R
import com.laze.mywanandroid.bean.ArticleData

/**
 * create by Laze1
 * on 2020/7/27-11:33
 */
class ArticleAdapter(layoutId:Int):BaseQuickAdapter<ArticleData,BaseViewHolder>(layoutId),
    LoadMoreModule {
    override fun convert(holder: BaseViewHolder, item: ArticleData) {

        holder.setText(R.id.tvArticleTitle,item.title)
            .setText(R.id.tvArticleAuthor,if(item.author.isBlank()) item.shareUser else item.author)
            .setText(R.id.tvArticleTime,item.niceDate)
        //初始化，防止item图标错乱
        holder.getView<ImageView>(R.id.imgCollect).drawable.setTint(ContextCompat.getColor(context,R.color.collectColorDefault))
        if (item.collect){
            holder.getView<ImageView>(R.id.imgCollect).drawable.setTint(ContextCompat.getColor(context,R.color.collectColorStar))
        }else{
            holder.getView<ImageView>(R.id.imgCollect).drawable.setTint(ContextCompat.getColor(context,R.color.collectColorDefault))
        }
        if (item.isTop){
            holder.setVisible(R.id.tvArticleTop,true)
        }else{
            holder.setGone(R.id.tvArticleTop,true)
        }
        holder.getView<ImageView>(R.id.imgCollect).setOnClickListener {
            // TODO: 2020/8/23 收藏/取下收藏点击事件
        }

    }
}